//
//  MYUserTool.m
//  奇闻
//
//  Created by 陈志铭 on 14-11-26.
//  Copyright (c) 2014年 MingYueGuCheng. All rights reserved.
//

#import "MYUserTool.h"
#import "MYAccountTool.h"
#import "MYHttpTool.h"
#import "MJExtension.h"
#import "MYUserParam.h"
#import "MYUser.h"
#import "MYUnReadResult.h"
#import "MYAccount.h"

@implementation MYUserTool
+ (void)userInfoDidSuccess:(void (^)(MYUser *))success failure:(void (^)(NSError *))failure
{
    MYUserParam *param = [MYUserParam param];
    param.uid = [MYAccountTool account].uid;
    //模型转字典
    [MYHttpTool GET:@"https://api.weibo.com/2/users/show.json" parameters:param.keyValues success:^(id responseObject) {
        //字典转模型
        MYUser *user = [MYUser objectWithKeyValues:responseObject];
        //获取账号模型
        MYAccount *account = [MYAccountTool account];
        account.name = user.name;
        //存储账号
        [MYAccountTool save:account];
        if (success) {
            success(user);
        }
    } failure:^(NSError *error) {
        if (failure) {
            failure(error);
        }
    }];
}
+ (void)unReadCountDidSuccess:(void (^)(MYUnReadResult *))success failure:(void (^)(NSError *))failure
{
    MYUserParam *param = [MYUserParam param];
    param.uid = [MYAccountTool account].uid;
    //模型转字典
    [MYHttpTool GET:@"https://rm.api.weibo.com/2/remind/unread_count.json" parameters:param.keyValues success:^(id responseObject) {
        MYUnReadResult *unReadResult = [MYUnReadResult objectWithKeyValues:responseObject];
        if (success) {
            success(unReadResult);
        }
    } failure:^(NSError *error) {
        if (failure) {
            failure(error);
        }
    }];
}
@end
